﻿// (c) Copyright Michael Antonio.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved
using System;
using System.Linq;
using Microsoft.Phone.Controls;
using Subsonic.Controls;
using Subsonic.Data;
using Subsonic.ViewModels;
using MichMan.Utilities;

namespace Subsonic.Pages
{
    public partial class AlbumsPivot : MediaApplicationPage
    {
        public AlbumsPivot()
        {
            InitializeComponent();
        }

        PivotViewModel AlbumsViewModel
        {
            get
            {   
                return (PivotViewModel)DataContext;
            }
        }

        string AlbumId { get; set; }
        string ArtistId { get; set; }
        AlbumListType AlbumListType { get; set; }

        protected override PivotViewModel CreateViewModel(string firstPivotId)
        {
            string artistId;
            AlbumListType albumListType;
            PivotViewModel pvm = null;

            if (firstPivotId == null)
            {
                NavigationContext.QueryString.TryGetValue("albumId", out firstPivotId);
            }
            AlbumId = firstPivotId;

            if (NavigationContext.QueryString.TryGetValue("artistId", out artistId))
            {
                ArtistId = artistId;

                pvm = new ArtistAlbumsViewModel(artistId, AlbumId);
            }
            else if (NavigationContext.QueryString.TryGet<AlbumListType>("albumListType", out albumListType))
            {
                AlbumListType = albumListType;
                pvm = new AlbumListViewModel(albumListType, AlbumId);
            }

            return pvm;
        }
    }
}